package com.situ.day24;

import com.situ.day23.Teacher;
import com.situ.day4.Student;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

public class GenericDemo {
    @Test
    public void test1() {
        List<String> list = new ArrayList();
        list.add("java");
        //list.add(2);

        //String str = (String) list.get(0);
        String str = list.get(0);
    }

    @Test
    public void test2() {
        //两端的类型必须要一致
        List<Object> list1 = new ArrayList<Object>();
        List<String> list2 = new ArrayList<String>();

        //右侧的泛型可以不写
        List<String> list3 = new ArrayList<>();
        //只写右侧泛型泛型是不起作用
        List list4 = new ArrayList<String>();
        list4.add(3);

        //两边不一致变异时候报错
        //List<Integer> list5 = new ArrayList<String>();
        //泛型里面必须是引用数据类型
        //List<int> list6 = new ArrayList<>();

    }

    @Test
    public void test5() {
        List<String> list1 = new ArrayList<String>();  //创建泛型
        List<Integer> list2 = new ArrayList<Integer>();
        Class c1 = list1.getClass();  //获取泛型的类型
        Class c2 = list2.getClass();
        System.out.println(c1 == c2); //输出true
    }

    public void add1(List<Student> list) {

    }

    public void add(List<Teacher> list) {

    }

}
